package com.atguigu.gmallsugar.controller;

import com.atguigu.gmallsugar.service.TradeService;
import com.atguigu.gmallsugar.service.TrafficService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

/**
 * @Author lzc
 * @Date 2023/8/14 14:29
 */
@RestController
public class SugarController {
    
    @Autowired
    TradeService tradeService;
    @RequestMapping("/sugar/trade/gmv")
    public String gmv(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
        
        
        return tradeService.gmv(date);
    }
    
    @RequestMapping("/sugar/trade/gmv/spu")
    public String gmvBySpu(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
    
        return tradeService.gmvBySpu(date);
    }
    
    
    @RequestMapping("/sugar/trade/gmv/tm")
    public String gmvByTm(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
        
        return tradeService.gmvByTm(date);
    }
    
    @RequestMapping("/sugar/trade/refund")
    public String refund(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
        
        return tradeService.category3Stat(date);
    }
    
    @Autowired
    TrafficService trafficService;
    @RequestMapping("/sugar/traffic/hour")
    public String traffic(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
        
        return trafficService.statTraffic(date);
    }
    
    
    @RequestMapping("/sugar/trade/province")
    public String province(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
    
        return tradeService.province(date);
    }
    
    @RequestMapping("/sugar/traffic/kw")
    public String kw(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()));
        }
        
        return trafficService.kw(date);
    }
}
